<?php


namespace App\Http\Controllers\admin;


use App\Http\Controller;
use App\Services\Code;
use App\Services\OssServices;

/**
 * Class BaseController
 * @package App\Http\Controllers\admin
 * author:admin
 * desc:公共控制器
 * created_at: {2020/10/16}----10:38 上午
 */
class BaseController extends Controller
{

    private $arr_ext = [
        'file'=>['png','jpg','jpeg','gif'],
        'video'=>['mp4','avi'],
    ];


    public function local1(){
        $file=$_FILES["upfile"];
        $filePath = $file["tmp_name"];
        $ext = substr($file['name'],strrpos($file['name'],'.')+1); // 上传文件后缀
        $object=date('YmdHis').'-'.time().'.'.$ext;
        $oss = new OssServices();
        $url = $oss->upload($object,$filePath);
        $arr =[
            'url' => $url,
            'original' => $file['name'],
            'size' => $file['size'],
            'state' => 'SUCCESS',
            'title' => $file['name'],
            'type' => $file['type'],
        ];
        return json_encode($arr);

    }
    public function file_up(): array
    {
        ini_set('memory_limit','2048M');
        set_time_limit(0);
        $filePath = $_FILES["file"]["tmp_name"];
        $ext = substr($_FILES['file']['name'],strrpos($_FILES['file']['name'],'.')+1); // 上传文件后缀
        $accept = request('accept');
//        if(!in_array(strtolower($ext),$this->arr_ext[$accept])){
//            return Code::message('文件格式不正确!!',301);
//        }
        $object=date('YmdHis').'-'.time().'.'.$ext;
        $oss = new OssServices();
        $url = $oss->upload($object,$filePath);
        return Code::message('',200,[
            'src'=>$url
        ]);

    }


    public function file_up2(){
        $path = request()->file('file')->store('');
//        print_r($path);exit;
        return Code::message('',200,[
            'src'=>'http://'.$_SERVER['HTTP_HOST'].'/qr_code/'.$path
        ]);
    }

}
